import click
import config
import os
import faceRecognise as fr
import json
import traceback


@click.command()
@click.option('--path', '-p', type=str)
@click.option('--dir', '-d')
@click.option('--strict', '-s', default=config.detectstrict, type=float)
def detect(path: str, dir, strict):
    try:
        if not os.path.exists(path):
            print('no valid image path:', path)
            return False
        encodings = fr.loadFaceEncoding(dir)
        img = fr.loadImg(path)
        r = fr.detectFace(img, encodings, strict)
        print(r)
        return r
    except Exception as me:
        print("ERR:")
        print('traceback.print_exc(): ', traceback.print_exc())
